<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录</title>
    <!--    <link rel="stylesheet" href="__STATIC__/admin/css/login.css">-->
    <link rel="stylesheet" href="__STATIC__/admin/css/login.css">
    <!-- 作者QQ:951252660 -->
</head>

<body>
<div class="login">
    <div class="center">
        <h1>Login</h1>
        <div class="inputLi">
            <strong>账户</strong>
            <input type="text" placeholder="your name" name="username" id="username" value="">
        </div>
        <div class="inputLi">
            <strong>密码</strong>
            <input type="password" placeholder="请输入密码" name="password" id="password">
        </div>
        <div class="inputLi">
            <strong>验证码</strong>
            <input type="text" placeholder="请输入验证码" name="code" id="code">
            <img src="{:captcha_src()}" alt="" id="codeImg">
        </div>

        <input type="checkbox" name="isLogin" value="1" id="isLogin"> 3天免登录

        <div class="inputLi">
            <!--                <input type="submit" value="登录">-->
            <button id="login">登录</button>
        </div>
    </div>
</div>
</body>
</html>
<script src="__STATIC__/admin/js/jquery-3.1.1.min.js"></script>
<script>

    $('#codeImg').click(function () {
        this.src = '{:captcha_src()}?' + Math.random(); //浏览器兼容问题 需增加随机数
    })

    $('#login').click(function () {
        var username = $('#username').val();
        var password = $('#password').val();
        var code = $('#code').val();
        var isLogin = $('#isLogin:checked').val();

        $.ajax({
            "url": "http://www.1906a.com/login",//入口 生成token
            "type": "POST",
            "data": {
                'username': username,
                'password': password,
                'code': code,
                'isLogin': isLogin,
                '__token__': "{$Request.token}",//表单令牌  表单重复提交，防止接口刷新
            },
            "dataType": "JSON",
            "success": function (res) {
                console.log(res);
                if (res.code == 200) {
                    alert('登录成功');
                    //存储本地缓存
                    localStorage.setItem('token', res.data.token);
                    window.location.href = "http://www.1906a.com/admin/index/index?token=" + res.data.token;
                }
            },
            "error": function (error) {
                console.log(error);
            },
        })
    })
</script>